import { get } from '@/api/common'

export default {
  // 获得申请记录
  getApplys(areaValue, hospitalValue, addrSearch,cb,errCb) {
    let body = {
        '@column': 'id,hope_addr,conn_person,conn_phone,checkin_num,checked,region_id,checkin_reson,remark,hotel_id,hospital_id,date_begin,date_end,keyword',
        '@order': 'date_begin-',
        };
    if(areaValue>0)
      body['region_id'] = areaValue;
    if(hospitalValue>0)
      body['hospital_id'] = hospitalValue;
    if(addrSearch!='')
      body['hope_addr$'] = '%'+addrSearch+'%';
    let params = {
      '[]': {
        'Wh_subscribe': body,
        'Dicts':{
          '@column': 'value,name',
          'value@': '/Wh_subscribe/region_id',
          'object': 'wh_hotel',
          'field': 'checkin_area'
        },
        'Wh_hotel': {
          '@column': 'id,hotel_name,address',
          'id@': '/Wh_subscribe/hotel_id',
        },
        'Wh_hospital': {
          '@column': 'id,hospital_name',
          'id@': '/Wh_subscribe/hospital_id',
        }
      }
    };
    get(params,cb,errCb);
  },
  // 添加或修改申请信息
  editApply (apply, cb, errCb) {
      let params = {
        'Wh_chi': apply,
        'tag': 'Wh_hotel'
      }
      let fun = null
      if(apply.id>0)
        fun = update
      else
        fun = insert
      fun(params)
        .then( res=> {
          var b = res.data.code==200&&res.data.msg=='success'
          b?cb():errCb()
        })
        .catch(function (err){
          console.log('error:'+err);
        });
  },

}